package vn.orderonline.web.client.service;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.GrantedAuthority;
import org.springframework.security.core.authority.SimpleGrantedAuthority;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.security.core.userdetails.User;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.security.core.userdetails.UsernameNotFoundException;
import org.springframework.stereotype.Service;

import vn.orderonline.com.core.business.acountadmin.IAccountAdminManager;
import vn.orderonline.com.core.business.dto.AdminDto;

@Service
public class CustomMemberDetailsService implements UserDetailsService {

	@Autowired
	private IAccountAdminManager iAccountAdminManager;

	public UserDetails loadUserByUsername(String username)
			throws UsernameNotFoundException {
		AdminDto adminDto = iAccountAdminManager.getAdminByAdminLoginId(username);
		boolean enabled = true;
		boolean accountNonExpired = true;
		boolean credentialsNonExpired = true;
		boolean accountNonLocked = true;
		List<GrantedAuthority> authList = new ArrayList<GrantedAuthority>();
		authList.add(new SimpleGrantedAuthority(adminDto.getRoleName()));		
		return new User(adminDto.getAdminLoginId(),
		adminDto.getAdminPassword(), enabled, accountNonExpired,
		credentialsNonExpired, accountNonLocked, authList);
	}

}
